//
//  TransferDetailViewController.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/17.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "TransferDetailViewController.h"
#import "TsfDetailCell.h"
#import "TsfDetailHeader.h"
#import "CYXBaseRequest.h"
#import "TsfDetailModel.h"

@interface TransferDetailViewController ()
/// <#注释#>
@property (nonatomic, strong) TsfDetailModel *tsfDetailM;

/// <#注释#>
@property (nonatomic, strong) TsfDetailHeader *header;
@end

@implementation TransferDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self getTsfDetail];
}

- (void)setupUI{
    [super setupUI];
    self.title = [self.tsfType isEqualToString:@"SEND"] ? @"转出详情" : @"转入详情";
    [self.tableView registerNib:[UINib nibWithNibName:@"TsfDetailCell" bundle:nil] forCellReuseIdentifier:@"TsfDetailCell"];
    self.header = [[TsfDetailHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 185)];
    self.tableView.tableHeaderView = self.header;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return self.tsfDetailM.infoList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *info = self.tsfDetailM.infoList[indexPath.row];
    TsfDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TsfDetailCell"];
    cell.title.text = info[@"title"];
    cell.info.text = info[@"info"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

- (void)getTsfDetail{
    NSString *api = [self.tsfType isEqualToString:@"SEND"] ? API_getTsfLogSendDetail : API_getTsfLogReceiveDetail;
//    API_getTsfLogSendDetail;
//    API_getTsfLogReceiveDetail;
    
        NSDictionary *param = @{@"transactionId":@(self.tsfId)};
    
        [CYXBaseRequest postWithUrl:api param:param resultClass:[TsfDetailModel class] success:^(id res) {
            if ([res isEqual: RequestErrorCode]) {
                
            }else{
                self.tsfDetailM = res;
                [self.tsfDetailM configInfoList];
                [self.header refersh:self.tsfDetailM];
                [self.tableView reloadData];
            }
            
            CYXLog(@"%@",res)
        } failure:^(NSError *error) {
            CYXLog(@"%@",error)
        }];
}

@end
